package com.gzz.manage.base.customeraddr;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.gzz.common.base.Page;
import com.gzz.common.config.Result;

/**
 * @类说明 【收货地址表】控制器
 * @author 高振中
 * @date 2021-03-14 00:17:40
 **/
//@Slf4j
@RestController
@RequestMapping("customerAddr")
public class CustomerAddrController {

	@Autowired
	private CustomerAddrService customerAddrService; // 注入【收货地址表】业务逻辑层

	/**
	 * @方法说明 【收货地址表】新增
	 */
	@PostMapping("save")
	public Result<Integer> save(@RequestBody @Validated CustomerAddr customerAddr) {
		if (customerAddrService.count(CustomerAddrCond.builder().nameEq(customerAddr.getName()).build()) > 0)
			return Result.error(1, "【收货地址表名称】不能重复！");
		return Result.success(customerAddrService.save(customerAddr));
	}

	/**
	 * @方法说明 【收货地址表】删除
	 */
	@PostMapping("delete")
	public Result<Integer> delete(@RequestBody Object[] ids) {
		return Result.success(customerAddrService.delete(ids));
	}

	/**
	 * @方法说明 【收货地址表】修改
	 */
	@PostMapping("update")
	public Result<Integer> update(@RequestBody @Validated CustomerAddr customerAddr) {
		if (customerAddrService.count(CustomerAddrCond.builder().nameEq(customerAddr.getName()).idNe(customerAddr.getId()).build()) > 0)
			return Result.error(1, "【收货地址表名称】不能重复！");
		return Result.success(customerAddrService.update(customerAddr));
	}

	/**
	 * @方法说明 【收货地址表】分页列表
	 */
	@PostMapping("page")
	public Result<Page<CustomerAddr>> page(@RequestBody CustomerAddrCond cond) {
		return Result.success(customerAddrService.page(cond));
	}

	/**
	 * @方法说明 【收货地址表】列表
	 */
	@PostMapping("list")
	public Result<List<CustomerAddr>> list(@RequestBody CustomerAddrCond cond) {
		return Result.success(customerAddrService.list(cond));
	}

	/**
	 * @方法说明 【收货地址表】按主键查
	 */
	@PostMapping("findById")
	public Result<CustomerAddr> findById(@RequestParam("id") Integer id) {
		return Result.success(customerAddrService.findById(id));
	}

	/**
	 * @方法说明 【收货地址表】个数
	 */
	@PostMapping("count")
	public Result<Integer> count(@RequestBody CustomerAddrCond cond) {
		return Result.success(customerAddrService.count(cond));
	}
}